package com.neo.rabbit;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 
 * 不处理路由键，只需要简单的将队里绑定到交换机上
 * 
 * 生产者将消息不是直接发送到队列，而是发送到X交换机，发送到交换机的消息都会被转发到与该交换机绑定的所有队列上
 * 
 * Fanout交换机转发消息是最快的
 * 
 * @author 00fly
 * @version [版本号, 2021年11月14日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Configuration
public class FanoutRabbitConfig
{
    @Bean
    public Queue AMessage()
    {
        return new Queue("fanout.A");
    }
    
    @Bean
    public Queue BMessage()
    {
        return new Queue("fanout.B");
    }
    
    @Bean
    public Queue CMessage()
    {
        return new Queue("fanout.C");
    }
    
    /**
     * 创建一个fanoutExchange交换机
     * 
     * @return
     * @see [类、类#方法、类#成员]
     */
    @Bean
    FanoutExchange fanoutExchange()
    {
        return new FanoutExchange("fanoutExchange");
    }
    
    /**
     * 队列绑定到fanoutExchange交换机
     * 
     * @param AMessage
     * @param fanoutExchange
     * @return
     * @see [类、类#方法、类#成员]
     */
    @Bean
    Binding bindingExchangeA(Queue AMessage, FanoutExchange fanoutExchange)
    {
        return BindingBuilder.bind(AMessage).to(fanoutExchange);
    }
    
    @Bean
    Binding bindingExchangeB(Queue BMessage, FanoutExchange fanoutExchange)
    {
        return BindingBuilder.bind(BMessage).to(fanoutExchange);
    }
    
    @Bean
    Binding bindingExchangeC(Queue CMessage, FanoutExchange fanoutExchange)
    {
        return BindingBuilder.bind(CMessage).to(fanoutExchange);
    }
}
